package com.whalefin.controller.adminUser;


import com.whalefin.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
* Created by sf on 14-4-28.
*/
@Controller
@RequestMapping("/adminUser/register")
public class RegisterController {

	@Autowired
	private LoginService loginService;

    @RequestMapping(method = RequestMethod.GET)
    public String login() {

        return "black/admin/adminLogin";

    }

	@RequestMapping(method = RequestMethod.POST)
	public String register(@RequestParam String loginName,@RequestParam String loginPassword) {

        int userCount = loginService.queryLoginUserByName(loginName);
        if(userCount > 0){
            return "black/admin/hello";
        }else{
            int result = loginService.register(loginName, loginPassword);
            if(result >= 0){
                return "redirect:/adminUser/loginSubmit";
            }else{
                return "redirect:/adminUser/loginSubmit";
            }
        }

	}
}
